<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="demo" index="1"></div>
    <script>
        div = document.querySelector('div');
        //设置元素的属性值法1：element.属性 = '值' 
        div.id = 'demo1';
        div.className = 'nav';
        console.log(div.id);
        console.log(div.className);


        //设置元素的属性值法2：element.setAttribute('属性','值')  只要针对自定义属性(标准)
        div.setAttribute('index','2');
        div.setAttribute('class','footer');
        console.log(div.getAttribute('index','2'));
        console.log(div.getAttribute('class','footer'));
    </script>
</body>
</html>